package com.yin.verify;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;
import javax.swing.filechooser.FileSystemView;

import net.minecraft.client.renderer.OpenGlHelper;

public class Verify {
	
	public final static String hwidUrl = "https://gitee.com/gaomutongxue/ayin-client-hwids/raw/master/hwids.txt";
	public static String hwidPath = null;
	
	static {
		File desktopDir = FileSystemView.getFileSystemView() .getHomeDirectory();
		String path = desktopDir.getAbsolutePath();
		hwidPath = path + "\\hwids.txt";
	}
	
	public static List<User> users = new ArrayList<User>();
	
	public static User verify() {
		
		updateUsers();
		
		User user = null;
		String hwid = Util.getHWID();
		
		for(User verifyUser : users) {
			if(verifyUser.hwid.equals(hwid)) {
				user = verifyUser;
			}
		}
		
		return user;
	}
	
	public static void updateUsers() {
		users = parse(Util.getUserInfo());
	}
	
	public static List<User> parse(List<String> userInfoList) {
		
		List<User> users = new ArrayList<User>();
		for(String userInfo : userInfoList) {
			
			String info[] = userInfo.split("_");
			String hwid = info[0];
			Permission permission = Permission.parsePermission(info[1]);
			String version = info[2];
			String username = info[3];
			
			users.add(new User(hwid, permission, version, username));
			
//			System.out.println(info);
//			System.out.println(info[0]);
//			System.out.println(info[1]);
//			System.out.println(info[2]);
//			System.out.println(info[3]);
		}
		
		return users;
	}
}
